Skip to content

fix: preserve image attributes when a title is present - #290

Merged
farnabaz merged 5 commits into
comarkdown:mainfrom
nimonian:fix/img-attributes-with-title
Jul 28, 2026
Merged

fix: preserve image attributes when a title is present#290
farnabaz merged 5 commits into
comarkdown:mainfrom
nimonian:fix/img-attributes-with-title

Conversation

@nimonian

Copy link
Copy Markdown
Contributor

Fixes #289.

The image stringify handler returns early on the title branch and never appends the attribute block, so ![alt](src "title"){width="200"} round-trips to ![alt](src "title"), dropping width, class, and every other attribute. The parser already keeps them (the tree carries width); only rendering was lossy.

The fix appends the collected attributes on both branches (one line in packages/comark/src/internal/stringify/handlers/img.ts).

Two commits, so the regression is visible on its own:

  1. a failing test covering title + attribute images (the two controls pass, the two title+attribute cases fail)
  2. the one-line fix, turning the test green

Run the test:

pnpm --filter comark vitest run test/img-attributes.test.ts

Verified against current main: the new test is 4/4 green with the fix, and resolve-attributes / props / brackets stay green. Note: test/index.test.ts flakes independently of this change (some specs assert a 10ms parse budget that loses under CPU load), so it can fail intermittently on a clean main too.

🤖 Generated with Claude Code

nimonian and others added 2 commits July 25, 2026 17:15
The stringify handler for images returns early on the title branch and
never appends the attribute block, so `![alt](src "title"){width="200"}`
round-trips to `![alt](src "title")`, silently dropping width, class, and
every other attribute. The parser is fine (the tree keeps `width`); only
rendering is affected. Attributes-only and title-only images round-trip
correctly, so the two regression cases fail while the two controls pass.

Repro: pnpm --filter comark vitest run test/img-attributes.test.ts

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The image stringify handler returned early on the title branch and never
appended the attribute block, so `![alt](src "title"){width="200"}`
round-tripped to `![alt](src "title")`, dropping width, class, and every
other attribute. The parser already keeps them (the tree carries `width`);
only rendering was lossy. Append the attribute block on both branches.

Fixes the failing cases added in the previous commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nimonian
nimonian requested a review from farnabaz as a code owner July 25, 2026 16:20
@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@nimonian is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@farnabaz farnabaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@290

@comark/angular

npm i https://pkg.pr.new/@comark/angular@290

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@290

@comark/html

npm i https://pkg.pr.new/@comark/html@290

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@290

@comark/react

npm i https://pkg.pr.new/@comark/react@290

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@290

@comark/vue

npm i https://pkg.pr.new/@comark/vue@290

commit: 3b59047

@farnabaz

Copy link
Copy Markdown
Collaborator

Thanks @nimonian
Do you mind enabling Commits sign https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits and replace current commits with signed one? It is an organization organization rule.
Otherwise I can close this one and do it in another PR

@nimonian
nimonian force-pushed the fix/img-attributes-with-title branch from 0e94014 to a8cbc8f Compare July 28, 2026 00:15
@nimonian

Copy link
Copy Markdown
Contributor Author

Hi @farnabaz! The commits are now signed - hope it's ok now, let me know if there's any more I can do

@farnabaz
farnabaz merged commit 8d2171d into comarkdown:main Jul 28, 2026
3 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image attributes are dropped when title is provided

3 participants